package com.common.www.service.programme;


import org.springframework.boot.base.jpa.service.BaseLogicService;
import com.common.www.bean.entity.programme.ComparativeAnalysisRemark;
import com.common.www.repository.programme.ComparativeAnalysisRemarkRepository;
import com.common.www.utils.Md5Utils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class ComparativeAnalysisRemarkService extends BaseLogicService<ComparativeAnalysisRemark, Long> {

    @Autowired
    private ComparativeAnalysisRemarkRepository repository;

    @Override
    public ComparativeAnalysisRemarkRepository getRepository() {
        return repository;
    }

    /**
     * 生成keyHash
     * @param keyHashName
     * @return
     */
    public String generateKeyHash(String keyHashName) {
        //先生成keyHash
        String keyHash = "";
        if (StringUtils.isNotEmpty(keyHashName)){
            keyHash = Md5Utils.MD5Encode(keyHashName);
        }
        return keyHash;
    }


    /**
     * 根据key查询差异备注
     * @param type
     * @param keyHash
     * @param keyHashName
     * @return
     */
    public String getRemark(Integer type,String keyHash, String keyHashName) {
        ComparativeAnalysisRemark remarkObj = repository.getByTypeAndKeyHashAndKeyHashName(type, keyHash, keyHashName);
        if (remarkObj != null){
            return remarkObj.getRemark();
        }else {
            return "";
        }
    }

}
